/*
  学习目标：useEffect监听多个状态变化
*/
import React, { useState, useEffect } from 'react';

export default function App() {
  const [count, setCount] = useState(0);

  const [msg, setMsg] = useState('hello React');

  // 1. 分开监听
  useEffect(() => {
    document.title = count + msg;
    // eslint-disable-next-line react-hooks/exhaustive-deps
  }, [count]);

  useEffect(() => {
    document.title = count + msg;
    // eslint-disable-next-line react-hooks/exhaustive-deps
  }, [msg]);

  // 同时监听
  useEffect(() => {
    document.title = count + msg;
  }, [count, msg]);

  return (
    <div>
      <h1>{count}</h1>
      <button onClick={() => setCount(count + 1)}>+1</button>

      <hr />

      <h1>{msg}</h1>
      <button onClick={() => setMsg(msg + '~')}>+1</button>
    </div>
  );
}
